package com.work.formaldehyde.activity;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.umeng.analytics.MobclickAgent;
import com.work.formaldehyde.R;
import com.work.formaldehyde.activity_jianceshuju.COActivity;
import com.work.formaldehyde.activity_jianceshuju.No2Activity;
import com.work.formaldehyde.activity_jianceshuju.O3Activity;
import com.work.formaldehyde.activity_jianceshuju.PM10Activity;
import com.work.formaldehyde.activity_jianceshuju.PM25Activity;
import com.work.formaldehyde.activity_jianceshuju.So2Activity;
import com.work.formaldehyde.util.ApiUtils;
import com.work.formaldehyde.util.Url;
import com.work.formaldehyde.view.CircleProgress;

public class JianCeActivity extends AppCompatActivity implements View.OnClickListener {

    private Boolean kq = true, hw = true, kc = true, kz = true;

    private TextView dushu_text, good_text_activity, textlist_text, start_num_text, end_num_text;
    private RelativeLayout check_good_rela_activity;

    private CircleProgress circleProgress;

    //分享按钮
    private ImageView home_title_share, jiance_comeback;

    //六个显示的控件
    private View bottom_color, bottom_color2, bottom_color3, bottom_color4, bottom_color5, bottom_color6;
    private TextView youliang, youliang2, youliang3, youliang4, youliang5, youliang6, contaminated_text;
    private TextView youliang_textnum, youliang1_textnum, youliang_textnum3, youliang_textnum4, youliang_textnum5, youliang_textnum6, location_text;
    private LinearLayout kongqi, huwai, kaichuang, kouzhao;
    private TextView kongqis, huwais, kaichuangs, kouzhaos;
    private RelativeLayout reo3, reco, repm25, repm10, reno2, reso2;
    //四个朝向下方的箭头
    private ImageView loction_xia_img_one, loction_xia_img_two, loction_xia_img_the, loction_xia_img_four;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ApiUtils.ActivityIsLogin(this, 1);
        setContentView(R.layout.activity_zhiliang);
        if (ApiUtils.isNetworkConnected(JianCeActivity.this))
            inti();
    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    private int getValue = 0;
    private int progresscolor;

    /**
     * 初始化加载调用方法
     */
    public void inti() {
        Intent geti = getIntent();
        String aqi = geti.getStringExtra("value");
        if (!aqi.equals("null"))
            getValue = Integer.parseInt(aqi);
        dushu_text = findViewById(R.id.dushu_text);
        location_text = findViewById(R.id.location_text);
        dushu_text.setText(geti.getStringExtra("value"));
        contaminated_text = findViewById(R.id.contaminated_text);
        reo3 = findViewById(R.id.reo3);
        reco = findViewById(R.id.reco);
        repm25 = findViewById(R.id.repm25);
        repm10 = findViewById(R.id.repm10);
        reno2 = findViewById(R.id.reno2);
        reso2 = findViewById(R.id.reso2);
        reo3.setOnClickListener(this);
        reco.setOnClickListener(this);
        repm25.setOnClickListener(this);
        repm10.setOnClickListener(this);
        reno2.setOnClickListener(this);
        reso2.setOnClickListener(this);
        good_text_activity = findViewById(R.id.good_text_activity);
        textlist_text = findViewById(R.id.textlist_text);
        check_good_rela_activity = findViewById(R.id.check_good_rela_activity);
        check_good_rela_activity.setOnClickListener(this);
        if (getValue >= 0 && getValue <= 50) {
            progresscolor = 0xff61D77B;
            check_good_rela_activity.setBackgroundResource(R.color.contaminated_green);
        } else if (getValue >= 51 && getValue <= 100) {
            progresscolor = 0xffEEE648;
            check_good_rela_activity.setBackgroundResource(R.color.contaminated_yellow);
        } else if (getValue >= 101 && getValue <= 150) {
            progresscolor = 0xffE48233;
            check_good_rela_activity.setBackgroundResource(R.color.contaminated_orange);
        } else if (getValue >= 151 && getValue <= 200) {
            progresscolor = 0xffE33F23;
            check_good_rela_activity.setBackgroundResource(R.color.contaminated_red);
        } else if (getValue >= 201 && getValue <= 300) {
            progresscolor = 0xffB03DB3;
            check_good_rela_activity.setBackgroundResource(R.color.contaminated_violet);
        } else {
            progresscolor = 0xff931635;
            check_good_rela_activity.setBackgroundResource(R.color.contaminated_vermilion);
        }
        home_title_share = findViewById(R.id.home_title_share);
        home_title_share.setOnClickListener(this);
        jiance_comeback = findViewById(R.id.jiance_comeback);
        jiance_comeback.setOnClickListener(this);
        circleProgress = findViewById(R.id.circle_progress_bar1);
        circleProgress.setValue(getValue);
        circleProgress.setGradientColors(new int[]{progresscolor, progresscolor});
        start_num_text = findViewById(R.id.start_num_text);
        end_num_text = findViewById(R.id.end_num_text);
        start_num_text.setText("" + getValue);
        //六个显示控件
        bottom_color = findViewById(R.id.bottom_color);
        bottom_color2 = findViewById(R.id.bottom_color2);
        bottom_color3 = findViewById(R.id.bottom_color3);
        bottom_color4 = findViewById(R.id.bottom_color4);
        bottom_color5 = findViewById(R.id.bottom_color5);
        bottom_color6 = findViewById(R.id.bottom_color6);
        youliang = findViewById(R.id.youliang);
        youliang2 = findViewById(R.id.youliang2);
        youliang3 = findViewById(R.id.youliang3);
        youliang4 = findViewById(R.id.youliang4);
        youliang5 = findViewById(R.id.youliang5);
        youliang6 = findViewById(R.id.youliang6);
        youliang_textnum = findViewById(R.id.youliang_textnum);
        youliang1_textnum = findViewById(R.id.youliang1_textnum);
        youliang_textnum3 = findViewById(R.id.youliang_textnum3);
        youliang_textnum4 = findViewById(R.id.youliang_textnum4);
        youliang_textnum5 = findViewById(R.id.youliang1_textnum5);
        youliang_textnum6 = findViewById(R.id.youliang_textnum6);
        //四个按钮
        kongqi = findViewById(R.id.kongqi);
        kongqi.setOnClickListener(this);
        huwai = findViewById(R.id.huwai);
        huwai.setOnClickListener(this);
        kaichuang = findViewById(R.id.kaichuang);
        kaichuang.setOnClickListener(this);
        kouzhao = findViewById(R.id.kouzhao);
        kouzhao.setOnClickListener(this);
        kongqis = findViewById(R.id.kongqis);
        huwais = findViewById(R.id.huwais);
        kaichuangs = findViewById(R.id.kaichuangs);
        kouzhaos = findViewById(R.id.kouzhaos);
        //向下的箭头
        loction_xia_img_one = findViewById(R.id.loction_xia_img_one);
        loction_xia_img_two = findViewById(R.id.loction_xia_img_two);
        loction_xia_img_the = findViewById(R.id.loction_xia_img_the);
        loction_xia_img_four = findViewById(R.id.loction_xia_img_four);
        kongqi_mas = findViewById(R.id.kongqi_mas);
        huwai_mas = findViewById(R.id.huwai_mas);
        kaichuang_mas = findViewById(R.id.kaichang_mas);
        kouzhao_mas = findViewById(R.id.kouzhao_mas);
        textlist_text.setText(geti.getStringExtra("zhibiao"));
        contaminated_text.setText(geti.getStringExtra("wuranwu"));
        youliang_textnum.setText(geti.getStringExtra("pm10"));
        youliang1_textnum.setText(geti.getStringExtra("no2"));
        youliang_textnum3.setText(geti.getStringExtra("so2"));
        youliang_textnum4.setText(geti.getStringExtra("pm25"));
        youliang_textnum5.setText(geti.getStringExtra("co"));
        youliang_textnum6.setText(geti.getStringExtra("o3"));
        if (!Url.ADDRESSCITY.equals(""))
            location_text.setText(Url.ADDRESSCITY);
        else
            location_text.setText("未能获取定位信息");
    }

    private TextView kongqi_mas, huwai_mas, kaichuang_mas, kouzhao_mas;

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.check_good_rela_activity:
                Intent toxdw = new Intent(JianCeActivity.this, WuRanActivity.class);
                startActivity(toxdw, ActivityOptions.makeSceneTransitionAnimation(JianCeActivity.this).toBundle());
                break;
            case R.id.home_title_share:
                break;
            case R.id.kongqi:
                loction_xia_img_one.setPivotX(loction_xia_img_one.getWidth() / 2);
                loction_xia_img_one.setPivotY(loction_xia_img_one.getHeight() / 2);
                if (kq) {
                    loction_xia_img_one.animate().rotation(180);
                    kongqi_mas.setVisibility(View.VISIBLE);
                    kq = false;
                } else {
                    loction_xia_img_one.animate().rotation(360);
                    kongqi_mas.setVisibility(View.GONE);
                    kq = true;
                }
                break;
            case R.id.huwai:
                loction_xia_img_two.setPivotX(loction_xia_img_two.getWidth() / 2);
                loction_xia_img_two.setPivotY(loction_xia_img_two.getHeight() / 2);
                if (hw) {
                    loction_xia_img_two.animate().rotation(180);
                    huwai_mas.setVisibility(View.VISIBLE);
                    hw = false;
                } else {
                    loction_xia_img_two.animate().rotation(360);
                    huwai_mas.setVisibility(View.GONE);
                    hw = true;
                }
                break;
            case R.id.kaichuang:
                loction_xia_img_the.setPivotX(loction_xia_img_the.getWidth() / 2);
                loction_xia_img_the.setPivotY(loction_xia_img_the.getHeight() / 2);
                if (kc) {
                    loction_xia_img_the.animate().rotation(180);
                    kaichuang_mas.setVisibility(View.VISIBLE);
                    kc = false;
                } else {
                    loction_xia_img_the.animate().rotation(360);
                    kaichuang_mas.setVisibility(View.GONE);
                    kc = true;
                }
                break;
            case R.id.kouzhao:
                loction_xia_img_four.setPivotX(loction_xia_img_four.getWidth() / 2);
                loction_xia_img_four.setPivotY(loction_xia_img_four.getHeight() / 2);
                if (kz) {
                    loction_xia_img_four.animate().rotation(180);
                    kouzhao_mas.setVisibility(View.VISIBLE);
                    kz = false;
                } else {
                    loction_xia_img_four.animate().rotation(360);
                    kouzhao_mas.setVisibility(View.GONE);
                    kz = true;
                }
                break;
            case R.id.jiance_comeback:
                onBackPressed();
                break;
            case R.id.reo3:
                Intent reo3 = new Intent(JianCeActivity.this, O3Activity.class);
                startActivity(reo3, ActivityOptions.makeSceneTransitionAnimation(JianCeActivity.this).toBundle());
                break;
            case R.id.reco:
                Intent reco = new Intent(JianCeActivity.this, COActivity.class);
                startActivity(reco, ActivityOptions.makeSceneTransitionAnimation(JianCeActivity.this).toBundle());
                break;
            case R.id.repm25:
                Intent repm25 = new Intent(JianCeActivity.this, PM25Activity.class);
                startActivity(repm25, ActivityOptions.makeSceneTransitionAnimation(JianCeActivity.this).toBundle());
                break;
            case R.id.repm10:
                Intent repm10 = new Intent(JianCeActivity.this, PM10Activity.class);
                startActivity(repm10, ActivityOptions.makeSceneTransitionAnimation(JianCeActivity.this).toBundle());
                break;
            case R.id.reno2:
                Intent reno2 = new Intent(JianCeActivity.this, No2Activity.class);
                startActivity(reno2, ActivityOptions.makeSceneTransitionAnimation(JianCeActivity.this).toBundle());
                break;
            case R.id.reso2:
                Intent reso2 = new Intent(JianCeActivity.this, So2Activity.class);
                startActivity(reso2, ActivityOptions.makeSceneTransitionAnimation(JianCeActivity.this).toBundle());
                break;
        }
    }
}
